class Singleton {
    //这里的static的必要性是，在静态方法中引用了该变量
    private static _instance: Singleton | null = null
    //无法通过构造函数实例化
    protected constructor() {

    }
    //这里的static的必要性是，使用类直接访问改函数
    static instanceof(): Singleton {
        if (this._instance === null) {
            this._instance = new Singleton()
        }
        return this._instance
    }
}
class Singleton2 {
    //这里的static的必要性是，在静态方法中引用了该变量
    private static _instance: Singleton2 | null = null
    declare private static _registry: Map<string, Singleton2>

    static {
        this.register('single', new Singleton2())
        console.log('jingtaik');
    }
    //无法通过构造函数实例化
    protected constructor() {

    }
    //这里的static的必要性是，使用类直接访问改函数
    static instance(): Singleton2 {
        if (this._instance === null) {
            const name = "single"
            this._instance = this.lookUp(name)
        }
        return this._instance
    }
    static register(name: string, singleton: Singleton2) {
        this._registry.set(name, singleton)
    }
    protected static lookUp(name: string): Singleton2 {
        return this._registry.get(name)!
    }
}

const s = Singleton.instanceof()
const s1 = Singleton.instanceof()
console.log(s === s1);